package com.ita.acmsystem.merchant.service.impl;

import java.util.List;

import com.ita.acmsystem.merchant.dao.IMerchantDao;
import com.ita.acmsystem.merchant.dao.impl.MerchantDaoImpl;
import com.ita.acmsystem.merchant.entity.Merchant;
import com.ita.acmsystem.merchant.service.IMerchantService;

public class MerchantServiceImpl implements IMerchantService {

	private IMerchantDao dao;

	public MerchantServiceImpl() {
		super();
		dao = new MerchantDaoImpl();
	}

	public MerchantServiceImpl(IMerchantDao dao) {
		super();
		this.dao = dao;
	}

	@Override
	public boolean addMerchant(Merchant merchant) {

		if (dao.queryByName(merchant.getMerchantName()) == null) {
			return dao.persist(merchant) != null;
		}
		return false;
	}

	@Override
	public boolean deleteMerchant(String merchantId) {
		return dao.delete(merchantId);
	}

	@Override
	public boolean updateMerchant(Merchant merchant) {
		return dao.update(merchant);
	}

	@Override
	public Merchant getMerchantById(String merchantId) {
		return dao.queryById(merchantId);
	}

	@Override
	public List<Merchant> getAllMerchant() {
		return dao.queryAll();
	}

	@Override
	public Merchant login(String username, String password) {
		return dao.query(username, password);
	}

	public IMerchantDao getDao() {
		return dao;
	}

	public void setDao(IMerchantDao dao) {
		this.dao = dao;
	}

}
